#业务封装层，负责封装接口调用

class CASE:
    def __init__(self, session):
        self.session = session
    def My_return(self,response):
        response.encoding = 'utf-8'  # 修改获取结果的编码集
        # 获取状态码
        http_code = response.status_code  # http状态码
        body_code = response.text
        try:
            body_code = response.json()  # 尝试解析为JSON
        except Exception:
            # 如果不是JSON，就把原始响应放进去，方便调试
            body_code = {"msg": "非JSON响应", "raw": body_code}
        return {
            "http_code": http_code,
            "body_code": body_code,
        }
    ####################################################################################################################################
    def login(self,username,password):
        my_params = {
            'username': username,
            'password': password
        }
        my_url = "http://localhost:90/login/verifyLogin"  # 请求地址与参数
        # 发送登录请求，并获取相应结果
        response = self.session.get(url=my_url, params=my_params, timeout=5)  # get的参数在url里，使用params
        return self.My_return(response)
